import axios from 'axios'
// import { IS_DEV } from '@/config'
import loading from '@/config'
import getParamsFromUrl from 'get-params-from-url'
// let url = IS_DEV ? '这是开发环境的url' : '这是生产环境的url'
let time = new Date().getTime()

let Ax = axios.create({
  baseURL: '',
  timeout: 8000
})
// 在每次请求之前先拦截一下
Ax.interceptors.request.use(config => {
  console.log(config)
  console.log(loading)
  let noloading = getParamsFromUrl('noloading', config.url)
  console.log(noloading)
  loading.show()
  return config
}, err => {
  console.log(err)
  return Promise.reject(err)
})

Ax.interceptors.response.use(response => {
  loading.hide()
  return response
}, err => {
  return Promise.reject(err)
})

export function getNowPlaying (page = 1, count = 7) {
  let noloading = false
  if (page > 1) noloading = true
  return Ax.get(`/api/film/now-playing?__t=${time}&page=${page}&count=${count}&noloading=${noloading}`)
}

export function getComingSoon (page = 1, count = 7) {
  return Ax.get(`/api/film/coming-soon?__t=${time}&page=${page}&count=${count}`)
}

export function getFilmDetail (id) {
  return Ax.get(`/api/film/${id}?__t=${time}`)
}

export default Ax
